Skip to content

fix(core): Bound child span tracking on long-lived spans - #22916

Open
andreiborza wants to merge 3 commits into
developfrom
ab/fix-child-span-retention
Open

fix(core): Bound child span tracking on long-lived spans#22916
andreiborza wants to merge 3 commits into
developfrom
ab/fix-child-span-retention

Conversation

@andreiborza

@andreiborza andreiborza commented Jul 31, 2026

Copy link
Copy Markdown
Member

What

Bounds the child spans a span keeps a reference to. A child is no longer tracked when it could never show up in what that span sends:

  • the parent is unsampled, so its tree is never read
  • the parent is a segment span that has already been sent, on both the streaming and the transaction path
  • the parent already has 1000 children, which is the most a transaction carries

Late children still resolve their root span, so they keep being sent on their own.

Why

A span that outlives its children retains every one of them. In NestJS the Create Nest App span stays the active parent of anything a setInterval from a provider constructor starts, so those spans are never released and the process leaks around 80 MB/h.

Measured on a reproduction (60 s at 20 rps, post-GC heap snapshots), children retained on that span and heap node growth over the run:

retained node growth
before, span streaming (the default) 12000 +147%
before, transactions 12000 +152%
after 0 under +1%

Closes: #22860

A span keeps a strong reference to every child started under it, so a span that
outlives its children retains all of them. In NestJS the `Create Nest App` span
stays the active parent of anything a `setInterval` from a provider constructor
starts, which retains every span for the lifetime of the process.

Children are no longer tracked on an unsampled span, on a segment span whose
tree has already been serialized, or past the 1000 spans a transaction can
carry. Every child still records its root span, so late children are re-emitted
as their own transaction as before.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Comment thread packages/core/src/tracing/sentrySpan.ts
@github-actions

github-actions Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

⚠️ Warning: Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results. Try to re-run all tests to get up to date results.

Path Size % Change Change
@sentry/browser 29.93 kB - -
@sentry/browser - with treeshaking flags 28.13 kB - -
@sentry/browser (incl. Tracing) 47.23 kB +0.1% +43 B 🔺
@sentry/browser (incl. Tracing + Span Streaming) 47.25 kB +0.11% +49 B 🔺
@sentry/browser (incl. Tracing, Profiling) 52 kB +0.13% +67 B 🔺
@sentry/browser (incl. Tracing, Replay) 86.58 kB +0.08% +67 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 76 kB +0.09% +65 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 91.29 kB +0.08% +64 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 103.93 kB +0.06% +54 B 🔺
@sentry/browser (incl. Feedback) 47.24 kB - -
@sentry/browser (incl. sendFeedback) 34.77 kB - -
@sentry/browser (incl. FeedbackAsync) 39.87 kB - -
@sentry/browser (incl. Metrics) 31 kB - -
@sentry/browser (incl. Logs) 31.24 kB - -
@sentry/browser (incl. Metrics & Logs) 31.91 kB - -
@sentry/react 31.72 kB - -
@sentry/react (incl. Tracing) 49.48 kB +0.09% +43 B 🔺
@sentry/vue 34.91 kB +0.13% +45 B 🔺
@sentry/vue (incl. Tracing) 49.22 kB +0.12% +58 B 🔺
@sentry/svelte 29.96 kB - -
CDN Bundle 31.97 kB - -
CDN Bundle (incl. Tracing) 47.62 kB +0.1% +43 B 🔺
CDN Bundle (incl. Logs, Metrics) 33.52 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 48.98 kB +0.1% +46 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) 72.88 kB - -
CDN Bundle (incl. Tracing, Replay) 85.25 kB +0.06% +50 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 86.55 kB +0.08% +69 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 91.03 kB +0.08% +66 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.33 kB +0.06% +55 B 🔺
CDN Bundle - uncompressed 95.45 kB - -
CDN Bundle (incl. Tracing) - uncompressed 142.79 kB +0.09% +115 B 🔺
CDN Bundle (incl. Logs, Metrics) - uncompressed 100.16 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 146.77 kB +0.08% +115 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 224.92 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 262.05 kB +0.05% +115 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 266.01 kB +0.05% +115 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 275.75 kB +0.05% +115 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 279.71 kB +0.05% +115 B 🔺
@sentry/nextjs (client) 52.06 kB +0.07% +34 B 🔺
@sentry/sveltekit (client) 47.68 kB +0.11% +51 B 🔺
@sentry/core/server 79.94 kB +0.08% +58 B 🔺
@sentry/core/browser 51.86 kB +0.1% +47 B 🔺
@sentry/node 121.55 kB +0.04% +45 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 0 B added added
@sentry/node - without tracing 85.11 kB +0.08% +65 B 🔺
@sentry/aws-serverless 93.37 kB +0.05% +44 B 🔺
@sentry/cloudflare (withSentry) - minified 198.82 kB +0.08% +147 B 🔺
@sentry/cloudflare (withSentry) 489.28 kB +0.1% +451 B 🔺

View base workflow run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit c92f7f3. Configure here.

Comment thread packages/core/src/utils/spanUtils.ts
@andreiborza
andreiborza marked this pull request as ready for review July 31, 2026 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant